home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Performance Co-Pilot 1.3
/
SGI Performance Co-Pilot 1.3.iso
/
dist
/
pcp.idb
/
usr
/
pcp
/
bin
/
cron.pmdaily.z
/
cron.pmdaily
Wrap
Text File
|
1997-04-03
|
7KB
|
305 lines
#!/bin/sh
#
# Copyright 1995, Silicon Graphics, Inc.
# ALL RIGHTS RESERVED
#
# UNPUBLISHED -- Rights reserved under the copyright laws of the United
# States. Use of a copyright notice is precautionary only and does not
# imply publication or disclosure.
#
# U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
# Use, duplication or disclosure by the Government is subject to restrictions
# as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
# in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
# in similar or successor clauses in the FAR, or the DOD or NASA FAR
# Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
# 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
#
# THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
# INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
# DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
# PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
# GRAPHICS, INC.
#
# Example daily administrative script for PCP archive logs
#
# constant setup
#
tmp=/tmp/$$
status=0
trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
prog=`basename $0`
# control file for pmlogger administration ... edit the entries in this
# file to reflect your local configuration (see also -c option below)
#
CONTROL=/var/pcp/config/pmlogger/control
# default number of days to keep archive logs
#
CULLAFTER=14
# threshold size to roll /var/adm/pcplog/NOTICES
#
NOTICES=/var/adm/pcplog/NOTICES
ROLLNOTICES=20480
# determine real name for localhost
LOCALHOST=""
[ -x /usr/bsd/hostname ] && LOCALHOST=`/usr/bsd/hostname`
# option parsing
#
showme=false
usage="Usage: $prog [-c control] [-s size] [-k howlong]"
while getopts c:k:ns:? c
do
case $c
in
c) CONTROL="$OPTARG"
;;
k) CULLAFTER="$OPTARG"
check=`echo "$CULLAFTER" | sed -e 's/[0-9]//g'`
if [ "X$check" != "X" -a "X$check" != "Xforever" ]
then
echo "Error: -k option ($CULLAFTER) must be numeric"
status=1
exit
fi
;;
n) showme=true
;;
s) ROLLNOTICES="$OPTARG"
check=`echo "$ROLLNOTICES" | sed -e 's/[0-9]//g'`
if [ "X$check" != "X" ]
then
echo "Error: -s option ($ROLLNOTICES) must be numeric"
status=1
exit
fi
;;
?) echo "$usage"
status=1
exit
;;
esac
done
shift `expr $OPTIND - 1`
if [ $# -ne 0 ]
then
echo "$usage"
status=1
exit
fi
if [ ! -f $CONTROL ]
then
echo "$prog: Error: cannot find control file ($CONTROL)"
status=1
exit
fi
# each new archive log started by pmnewlog is named yymmdd.hh.mm
#
LOGNAME=`date "+%y%m%d.%H.%M"`
# each summarized log is named yymmdd
#
PREV_LOGNAME=`pmdate -1d %y%m%d`
_error()
{
_report Error "$1"
}
_warning()
{
_report Warning "$1"
}
_report()
{
echo "$prog: $1: $2"
echo "[$CONTROL:$line] ... logging for host \"$host\" unchanged"
touch $tmp.err
continue
}
# Roll /var/adm/pcplog/NOTICES -> /var/adm/pcplog/NOTICES.old if larger
# that 10 Kbytes
#
NOTICES=/var/adm/pcplog/NOTICES
if [ -s $NOTICES ]
then
if [ "`wc -c <$NOTICES`" -ge $ROLLNOTICES ]
then
echo "Roll $NOTICES -> $NOTICES.old"
echo "Start new $NOTICES"
if $showme
then
:
else
echo >>$NOTICES
echo "*** rotated by $prog: `date`" >>$NOTICES
mv -f $NOTICES $NOTICES.old
echo "Started by $prog: `date`" >$NOTICES
fi
fi
fi
# note on control file format version
# 1.0 was shipped as part of PCPWEB beta, and did not include the
# socks field [this is the default for backwards compatibility]
# 1.1 is the first production release, and the version is set in
# the control file with a $version=1.1 line (see below)
#
rm -f $tmp.err
line=0
version=1.0
cat $CONTROL \
| sed -e "s/LOCALHOSTNAME/$LOCALHOST/g" \
| while read host primary socks dir args
do
line=`expr $line + 1`
case "$host"
in
\#*|'') # comment or empty
continue
;;
\$*) # in-line shell command
cmd=`echo "$host $primary $socks $dir $args" | sed -e 's/^\\$//'`
eval $cmd
continue
;;
esac
if [ "$version" = "1.0" ]
then
args="$dir $args"
dir="$socks"
socks=n
fi
if [ ! -d $dir ]
then
_error "archive directory ($dir) does not exist"
continue
fi
cd $dir
echo
echo "=== daily maintenance of PCP archives for host $host ==="
echo
if [ "X$primary" = Xy ]
then
if [ "X$host" != "X$LOCALHOST" ]
then
_error "\"primary\" only allowed for $LOCALHOST (localhost, not $host)"
continue
fi
if /sbin/chkconfig pmlogger
then
:
else
_warning "primary logging disabled via chkconfig for $host"
continue
fi
pid=`ps -ef \
| sed -n \
-e '/grep/d' \
-e 's/$/ /' \
-e '/\/usr\/pcp\/bin\/pmlogger .*-P /p' \
| nawk '{print $2}'`
else
pid=`ps -ef \
| sed -n \
-e '/grep/d' \
-e 's/$/ /' \
-e "/\/usr\/pcp\/bin\/pmlogger .*-h *$host /p" \
| nawk '{print $2}'`
fi
if [ "X$pid" = X ]
then
_error "no pmlogger instance running for host \"$host\""
else
if [ "`echo $pid | wc -w`" -gt 1 ]
then
_error "multiple pmlogger instances running for host \"$host\", pids: $pid"
continue
fi
# now execute pmnewlog to "roll the archive logs"
#
[ "X$primary" != Xy ] && args="-p $pid $args"
[ "X$socks" = Xy ] && args="-s $args"
if $showme
then
echo "+ /usr/pcp/bin/pmnewlog $args $LOGNAME"
else
if /usr/pcp/bin/pmnewlog $args $LOGNAME
then
:
else
_error "problems executing pmnewlog for host \"$host\""
touch $tmp.err
fi
fi
fi
# concatenate yesterday's archive logs
#
echo
if [ -f $PREV_LOGNAME.0 -o -f $PREV_LOGNAME.index -o -f $PREV_LOGNAME.meta ]
then
echo "$prog: Warning: output archive ($PREV_LOGNAME) already exists"
echo "[$CONTROL:$line] ... skip log merging for host \"$host\""
continue
fi
if $showme
then
echo "+ /usr/pcp/bin/cron.pmlogmerge -f $PREV_LOGNAME'.??.??' $PREV_LOGNAME"
else
if /usr/pcp/bin/cron.pmlogmerge -f $PREV_LOGNAME'.??.??' $PREV_LOGNAME
then
:
else
_error "problems executing cron.pmlogmerge for host \"$host\""
fi
fi
# and cull old archives
#
if [ "X$CULLAFTER" != "Xforever" ]
then
echo "/^[0-9][0-9][0-1][0-9][0-3][0-9]\./!d" >$tmp.sed
i=0
while [ $i -le $CULLAFTER ]
do
echo "/^`pmdate -${i}d %y%m%d`\./d" >>$tmp.sed
i=`expr $i + 1`
done
LIST=`ls | sed -f $tmp.sed`
if [ "X$LIST" != X ]
then
echo "Archive files older than $CULLAFTER days being removed ..."
echo "$LIST" | fmt | sed -e 's/^/ /'
if $showme
then
:
else
echo "$LIST" | xargs rm -f
fi
fi
fi
done
[ -f $tmp.err ] && status=1
exit